package com.sample.library.web;

import android.app.Activity;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.just.agentweb.IWebLayout;
import com.sample.library.R;
import com.sample.library.widget.NestedScrollAgentWebView;


/**
 * Created by cenxiaozhong on 2017/8/14.
 */

public class SwipeRefreshWebLayout implements IWebLayout<NestedScrollAgentWebView, SwipeRefreshLayout> {

    private final SwipeRefreshLayout swipeRefreshLayout;
    private final NestedScrollAgentWebView mWebView;

    public SwipeRefreshWebLayout(Activity activity) {
        View mView = activity.getLayoutInflater().inflate(R.layout.layout_refresh_web, null);
        View smarkView = mView.findViewById(R.id.smarkLayout);
        swipeRefreshLayout = (SwipeRefreshLayout) smarkView;
        mWebView = mView.findViewById(R.id.webView);
        swipeRefreshLayout.setOnChildScrollUpCallback((swipeRefreshLayout, view) -> mWebView.getScrollY() > 0);
    }

    @NonNull
    @Override
    public SwipeRefreshLayout getLayout() {
        return swipeRefreshLayout;
    }

    @Nullable
    @Override
    public NestedScrollAgentWebView getWebView() {
        return mWebView;
    }


}
